package cn.com.ccxe.web.form;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import cn.com.ccxe.core.entity.MonitorType;

import com.ccxe.manage.service.CurrUserInfo;

public class KeywordActionForm extends ActionForm {
	private int id;
	private String text;
	private String method;
	private CurrUserInfo userInfo;
	private List<MonitorType> monitorTypes;
	private int monitorTypeId;
	
	public KeywordActionForm(HttpServletRequest request) {
		super(request);
	}

	@Override
	protected void reset() {
		String str_id = getParemetes("id");
		if(isEmpty(str_id)) {
			this.id = Integer.parseInt(str_id);
		}
		this.text = getParemetes("text");
		this.method = getParemetes("method");
		this.userInfo = (CurrUserInfo)getAttribute("currUser");
		this.monitorTypes = setMonitorType(getParameterValues("monitorTypes"));
		String str_monitorTypeId = getParemetes("monitorTypeId");
		if(isEmpty(str_monitorTypeId)) {
			this.monitorTypeId = Integer.parseInt(str_monitorTypeId);
		}
	}
	
	private boolean isEmpty(String str) {
		return !StringUtils.isEmpty(str);
	}

	public int getId() {
		return id;
	}
	public String getText() {
		return text;
	}
	public String getMethod() {
		return method;
	}
	public CurrUserInfo getUserInfo() {
		return userInfo;
	}
	public List<MonitorType> getMonitorTypes() {
		return monitorTypes;
	}
	
	private List<MonitorType> setMonitorType(String[] values) {
		if(values == null || values.length == 0) {
			return null;
		}
		List<MonitorType> monitorTypes = new ArrayList<MonitorType>();
		for (String id : values) {
			int i = Integer.parseInt(id);
			if(i > 0) {
				monitorTypes.add(new MonitorType(i));
			}
		}
		if(monitorTypes.size() > 0) {
			return monitorTypes;
		}
		return null;
	}

	public int getMonitorTypeId() {
		return monitorTypeId;
	}

}